package com.xgkj.diyiketang.activity.data;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.xgkj.diyiketang.activity.VideoDetailActivity;

import com.xgkj.diyiketang.data.OrderInfo;
import com.xgkj.diyiketang.util.ImageCache;
import com.xgkj.diyiketang.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrater on 2015/12/8.
 */
public class YueChangeAdapter extends BaseAdapter {
    private Context mContext;
    private List<OrderInfo> mList = new ArrayList<OrderInfo>();

    public YueChangeAdapter(Context context){
        mContext = context;
    }

    public void updateData(List<OrderInfo> list){
        if(mList != null){
            mList.addAll(list);
        }
        notifyDataSetChanged();
    }

    public void clearData(){
        if(mList != null){
            mList.clear();
        }

        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if(mList != null){
            return mList.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        if(mList != null && mList.size() >0){
            return mList.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ChildHolder childHolder = null;
        if(convertView == null){
            childHolder = new ChildHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.yuechange_item, null);
            childHolder.mType = (TextView)convertView.findViewById(R.id.yue_type);
            childHolder.mDate = (TextView) convertView.findViewById(R.id.yue_date);
            childHolder.mBanlance = (TextView) convertView.findViewById(R.id.yue_balance);
            childHolder.mFee = (TextView) convertView.findViewById(R.id.yue_fee);
            convertView.setTag(childHolder);
        }else{
            childHolder = (ChildHolder)convertView.getTag();
        }

        OrderInfo info = mList.get(position);
        if(info!=null){
            if(info.getType().equals("0")){
                childHolder.mType.setText("充值");
            }else if(info.getType().equals("2")){
                childHolder.mType.setText("退款");
            }else if(info.getType().equals("1")){
                childHolder.mType.setText("提现");
            }else if(info.getType().equals("3")){
                childHolder.mType.setText("余额支付");
            }else if(info.getType().equals("4")){
                childHolder.mType.setText("提现中");
            }

            childHolder.mDate.setText(info.getCompleteDate());
            childHolder.mBanlance.setText("余额："+info.getBalance());
            if(Double.parseDouble(info.getFee())<0){
                childHolder.mFee.setTextColor(mContext.getResources().getColor(R.color.sendbtn_enable));
                childHolder.mFee.setText(info.getFee());
            }else {
                childHolder.mFee.setTextColor(mContext.getResources().getColor(R.color.zhengshu));
                childHolder.mFee.setText(info.getFee());
            }

        }

        return convertView;
    }

    class ChildHolder{
        TextView mType;
        TextView mDate;
        TextView mBanlance;
        TextView mFee;
    }


}
